<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>添加User</title>
<link rel="stylesheet" href="../../js/layui/css/layui.css" media="all" />
<script src="../../js/layui/layui.js"></script>
</head>
<body>
	<form class="layui-form" onsubmit="return false;">
		<div class="layui-form-item">
			<label class="layui-form-mid">输入用户名:</label>
			<div class="layui-input-inline">
				<input type="text" name="u_name" placeholder="请输入用户"
					autocomplete="off" class="layui-input  search_input">
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-mid">输入密码:</label>
			<div class="layui-input-inline">
				<input type="text" name="u_password" placeholder="请输入密码"
					autocomplete="off" class="layui-input  search_input">
			</div>
		</div>

		<div class="layui-form-item">
			<button class="layui-btn" lay-submit lay-filter="formDemo">保存</button>
		</div>
	</form>

	<script type="text/javascript">
		layui.use(['form','layer'], function(){
		  var form = layui.form;
		  var layer = layui.layer;
		  var $ = layui.$;
		  
		  form.on('submit(formDemo)', function(data){
			  $.post('http://localhost:8080/FiveClothes/user/addUser',data.field,
					  function(res){
				  			var msg;
				  			if(res){
				  				msg="添加成功";
				  			}else{
				  				msg="添加失败";
				  			}
				  			layer.msg(msg, {
					  			  icon: 1,
					  			  time: 2000 //2秒关闭（如果不配置，默认是3秒）
					  			}, function(){
					  				var index = parent.layer.getFrameIndex(window.name);//获取窗口索引
									parent.layer.close(index);//关闭弹出层
									 window.parent.location.reload();//刷新父页面
					  			}); 
				  },'json');
			  return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
			});
		});
	 </script>

</body>
</html>